import React from 'react';
import Login from '@/pages/Login';
import {useHistory} from 'ice';
import {getCookieBBT, getCounter, invokeCounter, emptyCounter} from '@/utils/cookie';
import {loginByCookie} from '@/api/LoginAPI'
import Analysis from '@/pages/Analysis';
import UserTableListPage from '@/pages/UserTableListPage';
import { Message } from '@alifd/next';
import {PAGE_URL} from '@/api/ApiUrl'
// const mainPage = '/course/list';
// const login = '/login';
const login = PAGE_URL.LOGIN_PAGE;
const mainPage = PAGE_URL.MAIN_PAGE

class LoginInterceptor extends React.Component{
    constructor(props) {
      super(props);
      this.state = {
        isLogin: false,
      };
    }
    // 初始化方法
    componentDidMount(){
      console.log('初始化方法 LoginInterceptor')
      this.verifyLogin();

    };
    // 验证是否登录
    verifyLogin(){
      const bbt = getCookieBBT();
      let _isLogin = false;
      if(bbt){
        loginByCookie().then((data) => {
          if(data){
            console.log('loginByCookie data :::', data)
            if(data.status === 0){
              this.props.history.push(mainPage)
              return
            }
          }
          this.props.history.push(login)
        });
      }else{
        this.props.history.push(login)
      }
    }
    render(){
      return null;
    }
}
export default LoginInterceptor;